package com.wcy.scl.service;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ComputeService {
	
	private static Logger log = LogManager.getLogger(ComputeService.class);
	
	@Autowired
	private DiscoveryClient discoverClient;
	
	@Autowired
	Registration reg;

	@RequestMapping(value="add", method=RequestMethod.GET)
//	public int add(@RequestParam Integer x, @RequestParam Integer y){
	public int add(Integer x, Integer y){
		ServiceInstance instance = discoverClient.getLocalServiceInstance();
		int result = x + y;
		log.info("{}:{}:{} - call add method, the params x = {}, y = {}, x + y = {}", instance.getHost(), instance.getPort(), instance.getServiceId(), x, y, result);
		return result;
	}
}
